import java.awt.Color;
import lejos.nxt.Motor;
import lejos.nxt.remote.RemoteMotor;
import greenfoot.GreenfootImage;
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class LegoMotorB here.
 * 
 * @author (kos) 
 * @version (a version number or a date)
 */
public class LegoMotorB extends LegoMotorABC {

	boolean toggle_bool = true;
	private RemoteMotor motorB;
	private GreenfootImage image_text = new GreenfootImage(
			"images/legoMotorB.png");

	public LegoMotorB() {
		//  constructor 
		setImage(image_text);
		motorB = Motor.B;
	}

	/**
	 * Act - do whatever the LegoMotor wants to do. This method is called whenever
	 * the 'Act' or 'Run' button gets pressed in the environment.
	 */
	public void act() {
		rotate(50);
	}

	public void forward() {
		motorB.forward();
		update_image();
	}

	public void stop() {
		motorB.stop();
		update_image();
	}

	public void rotate(int pos) {
		motorB.rotate(pos, true);
		update_image();
	}

	public void update_image() {
		image_text.setColor(Color.WHITE);
		image_text.fillRect(2, 16, 43, 22); //erase part of image for new text
		image_text.setColor(Color.BLACK);
		image_text.drawString(Integer.toString(motorB.getTachoCount()), 2, 26);
	}

}
